import zipfile, pygame
from cStringIO import StringIO

class ZipDB:
    def __init__(self, filename):
        try:
            self.zipfile=zipfile.ZipFile(filename)
        except:
            raise SystemExit("cannot load DataBase archive "+filename)
    
    def GetFile(self, filename):
        """get file from archive"""
        data = self.zipfile.read(filename)
        data_io = StringIO(data)
        return data_io
    
    def GetImage(self, filename):
        """get image from archive"""
        return self.loadimg(self.GetFile(filename))
        
    def loadimg(self, filenameORobject):
        """load image and set colorkey"""
        img=pygame.image.load(filenameORobject).convert()
        img.set_colorkey((255, 0, 255))
        return img
